package pixeleditor.gui;

import java.io.File;
import java.util.List;
import java.util.ResourceBundle;

import javax.swing.Action;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import common.i18n.ChangeLanguage;
import common.i18n.IChangeLanguage;
import common.util.FileHandler;

import pixeleditor.ctrl.ControlFactory;

@SuppressWarnings("serial")
public class ChooseModePanel extends JPanel implements IChangeLanguage {
	private JComboBox mode;

	public ChooseModePanel() {
		ChangeLanguage.addObserver(this);
		initComponents();
		initControls();
	}

	private void initComponents() {
		setLanguage(ChangeLanguage.currentLanguage);

		//Add the different modes to a combobox
		String f = File.separator;
		List<String> modes = FileHandler.loadResources(
				"." + f +
				"pixelwaks" + f +
				"pixelwaks" + f +
				"plugins" + f +
				"modes", ".java");
		mode = new JComboBox(modes.toArray());
		
		add(mode);
	}

	private void initControls() {
		Action a = (Action) ControlFactory.getControl(ControlFactory.CHOOSE_MODE_CTRL);
		mode.setAction(a);
		a.putValue("ChooseMode.mode", mode);
	}

	@Override
	public void setLanguage(ResourceBundle rb) {
		setBorder(new TitledBorder(rb.getString("editorMode")));	
	}
}
